Accusoft.PdfXpress6.ActiveX
Load PDF from Memory

PDF Xpress™ supports opening a PDF document from memory.

To load an existing PDF file in memory:

  1. Create a new OpenOptions object.
  2. Create a new PdfDocument using a byte array containing the complete PDF file.
  3. Create a new Document using a handle to a Global Memory buffer containing the complete PDF file.
PDF Xpress can load any well-formed PDF up to PDF version 1.7. 
VB Example
Copy Code
'This code demonstrates loading a PDF document from memory
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (destination As Any, Source As Any, ByVal Length As Long)
On Error GoTo error
Dim pdfxpress1 As New Pdfxpress
pdfxpress1.Initialize
pdfxpress1.RaiseExceptions = True
Dim document As New PdfDocument
document.SetParentControl pdfxpress1
Dim hGlobal As Long  
Dim oo As New openOptions
'Prepare a global buffer loaded with Pdf data
Dim SizeInBytes As Long
SizeInBytes = FileLen("C:\test.pdf")      
Dim i As Integer
i = FreeFile
Open "C:\test.pdf" For Binary Access Read As i
Dim buffer() As Byte
buffer = InputB(SizeInBytes, i)
Close i
Const GMEM_MOVEABLE = &H2
Const GMEM_ZEROINIT = &H40
Const GHND = (GMEM_MOVEABLE Or GMEM_ZEROINIT)
Dim hGlobal As Long
hGlobal = GlobalAlloc(GHND, SizeInBytes)
Dim pBuffer As Long
pBuffer = GlobalLock(hGlobal)
CopyMemory ByVal pBuffer, buffer(0), SizeInBytes
GlobalUnlock hGlobal
'End of preparing global buffer 
Dim document As New PdfDocument
document.SetParentControl pdfxpress1
document.OpenDocumentFromHandle oo, hGlobal
.
.
.
GoTo finish
error:
MsgBox pdfxpress1.PdfError
finish:
Set document = Nothing
pdfxpress1.Terminate
Set pdfxpress1= Nothing
See Also

 

 


©2014. Accusoft Corporation. All Rights Reserved.

Send Feedback